package org.example.utils;

import org.activiti.bpmn.model.*;
import org.apache.commons.lang3.StringUtils;

public class ActivitiUtil {

    /**

     * 开始事件

     *

     * @return

     */

    public static StartEvent createStartEvent() {

        StartEvent startEvent = new StartEvent();
        startEvent.setId("start");
        return startEvent;
    }



    /**

     * 结束事件

     *

     * @return

     */

    public static EndEvent createEndEvent() {
        EndEvent endEvent = new EndEvent();
        endEvent.setId("end");
        return endEvent;
    }



    /**

     * 创建用户任务
     * @param id
     * @param name
     * @param assignee
     * @return
     */

    public static UserTask createUserTask(String id, String name, String assignee) {
        UserTask userTask = new UserTask();
        userTask.setName(name);
        userTask.setId(id);
        userTask.setAssignee(assignee);
        return userTask;
    }



    /**

     * 创建接收任务
     * @param id
     * @param name
     * @return
     */

    public static  ReceiveTask createReceiveTask(String id, String name) {
        ReceiveTask receiveTask = new ReceiveTask();
        receiveTask.setId(id);
        receiveTask.setName(name);
        return receiveTask;
    }

    /**
     * 连线
     * @param from
     * @param to
     * @return
     */
    public static SequenceFlow createSequenceFlow(String from, String to, String conditionExpression) {
        SequenceFlow sequenceFlow = new SequenceFlow();
        sequenceFlow.setSourceRef(from);
        sequenceFlow.setTargetRef(to);
        if (StringUtils.isNotBlank(conditionExpression)) {
            sequenceFlow.setConditionExpression(conditionExpression);
        }
        return sequenceFlow;
    }



    /**
     * 排他网关
     * @param id
     * @param name
     * @return
     */

    public static ExclusiveGateway createExclusiveGateway(String id, String name) {
        ExclusiveGateway exclusiveGateway = new ExclusiveGateway();
        exclusiveGateway.setId(id);
        exclusiveGateway.setName(name);
        return exclusiveGateway;
    }

    /**
     * 并行网关
     * @return
     */
    public static ParallelGateway createParallelGateway(String id, String name) {
        ParallelGateway parallelGateway = new ParallelGateway();
        parallelGateway.setId(id);
        parallelGateway.setName(name);
        return parallelGateway;
    }
}
